#ifndef _CONTROL_
#define _CONTROL_

#include "message.h"
#include "socket.h"
#include "list.h"
#include "filemanagement.h"

#define TIME_OUT 1 /* Segundos */
#define MAX_TRY 16

class FlowControl
{
    public:
        FlowControl(char *DEVICE = "eth0");
        bool receive(message *buffer, bool s = true);
        bool receive(message *buffer, byte typeAnswer, bool s = true);
        bool send(message *data, message *buffer, byte typeAnswer, bool waitAnswer = false,
                                bool sendACk = false);
        void sendAck();
        void sendNack();
        RawSocket * getRsDescriptor();
        bool sendUntilZ(byte *data, unsigned long int size, byte typeMessage,
                                byte typeAnswer);
        bool sendUntilZ(fileManagement *data, byte typeMessage, byte typeAnswer);
        bool receiveUntilZ(List *buffer, byte typeReceived, unsigned short seq);
        /*void receiveWithTimeOut(byte *data, unsigned long int size, byte typeMessage,
                         byte typeAnswerOriginally, byte typeAnswer, message *buffer);*/
    private:
        int waitTimeOut();
        RawSocket *rs;
};

#endif
